<?php
header('content-type:text/html;charset=utf-8');
$subject='king is king';
$pattern='#king#';
echo preg_match($pattern, $subject,$matches);
print_r($matches);
echo '<hr/>';
echo preg_match_all($pattern, $subject,$matches);
print_r($matches);
echo '<hr/>';
$subject="
    京东 http://www.jd.com
  天猫 https://tmall.com
 一号店 http://yhd.com
   麦子学院 http://maiziedu.com
   King的博客 http://phpfamily.org
    ";
$pattern='#(?:http|https)://\w+\.\w+(?:\.\w+)*#';
preg_match_all($pattern, $subject,$matches);
print_r($matches);
echo '<hr/>';
foreach($matches[0] as $val){
    $subject=str_replace($val,"<a href='{$val}' target='_blank'>{$val}</a>",$subject);
}
echo $subject;









